package com.xuanyuanxinyu.compose.ui.other

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.paddingFromBaseline
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

/**
 * @FileName:
 * @Description:
 * @author ken.luo
 * @date 2023/4/4
 * @version V1.0
 * @email 424533553@qq.com
 */
@Composable
fun WithConstraintsComposable(onClick : () -> Unit) {
    BoxWithConstraints(
        modifier = Modifier
            .padding(12.dp)
            .fillMaxWidth()
            .fillMaxHeight()
            // padding和Click的前后顺序是有关系的,clickable在前全局可点,clickable在后，出去padding部分才可点击
            .clickable(onClick = onClick)
    ) {
        Text(
            "My minHeight is $minHeight while my maxWidth is $maxWidth",modifier = Modifier
                //从布局顶部到基线保持特定距离
                .paddingFromBaseline(4.dp)
                // x、y轴偏移量
                .offset(x = 10.dp,y = 10.dp)
        )
    }
}
